package com.qingdai.addresscenter.service.impl;


import com.qingdai.addresscenter.mapper.AddressEsMapper;
import com.qingdai.business.emuns.Address;
import com.qingdai.business.emuns.AddressDTO;
import com.qingdai.business.service.AddressEsService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressEsServiceImpl implements AddressEsService {
    @Resource
    private AddressEsMapper addressEsMapper;
//    @Resource
//    private PlacesMapper placesMapper;

    @Override
    public Address getAddressById(Integer id) {
        return addressEsMapper.findByIdIs(id);
    }

//    @Override
//    public AddressDTO getAddressDTOById(Integer id) {
//        Address address = addressEsMapper.findByIdIs(id);
//        AddressDTO addressDTO = Address.toDTO(address);
//        Integer provinceId = address.getProvinceId();
//        Integer cityId = address.getCityId();
//        Integer districtId = address.getDistrictId();
//        Places places = placesMapper.selectById(provinceId);
//        Places city = placesMapper.selectById(cityId);
//        Places district = placesMapper.selectById(districtId);
//        addressDTO.setProvinceName(places.getCname());
//        addressDTO.setCityName(city.getCname());
//        addressDTO.setDistrictName(district.getCname());
//        return addressDTO;
//    }

    @Override
    public Address saveAddress(Address address) {
        Address save = addressEsMapper.save(address);
        return save;
    }

    @Override
    public Iterable<Address> saveAddresses(List<Address> address) {
        Iterable<Address> addressDTOS = addressEsMapper.saveAll(address);
        return addressDTOS;
    }
}
